import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreNoticeSmsLogService extends BaseService<any> {
  private readonly logger = new Logger(CoreNoticeSmsLogService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getPage
   * 对应 PHP: CoreNoticeSmsLogService_core::getPage()
   * 逻辑类型: undefined - undefined
   */
  async getPage(site_id: any[], where: any[]) {
    // 基于PHP真实逻辑: getPage
    // PHP原文: $field = 'id,mobile,sms_type,key,template_id,content,params,status,result,create_time,send_time,update_time';         $order = 'create_time desc';    ...
const field = 'id,mobile,sms_type,key,template_id,content,params,status,result,create_time,send_time,update_time';
        const order = 'create_time desc';
        const search_model = this.model.where([['site_id', '=', site_id))).withSearch(['name', 'key', 'mobile', 'sms_type', 'create_time'), where).field(field).order(order).append(['name', 'sms_type_name', 'status_name')];
        return this.pageQuery(search_model);
    }


    /**
     * 获取短信发送记录信息
     * @param int site_id
     * @param int id
     * @return */
    async getInfo(int site_id, int id)
    {
        const field = 'id, mobile,sms_type,key,template_id,content,params,status,result,create_time,send_time,update_time';
        return this.model.field(field).where([['id', '=', id], ['site_id', '=', site_id))).append(['name', 'sms_type_name', 'status_name')).findOrEmpty().toArray(];
    }

    /**
     * 添加短信发送记录
     * @param int site_id
     * @param data
     * @return mixed|null
     */
    async add(int site_id, data)
    {
        data.site_id = site_id;
        const log = this.model.create(data);
        return log?.id;

    }

    /**
     * 短信发送记录编辑
     * @param int site_id
     * @param int id
     * @param data
     * @return true
     */
    async edit(int site_id, int id, data)
    {
        data.update_time = time(];
        this.model.where([['id', '=', id], ['site_id', '=', site_id))).update(data);
        return true;
    }

    /**
     * 删除短信发送记录
     * @param int site_id
     * @param int id
     * @return bool
     */
    async del(int site_id, int id)
    {
        return this.model.where([['id', '=', id], ['site_id', '=', site_id))).delete(;
  }
  }

  /**
   * getInfo
   * 对应 PHP: CoreNoticeSmsLogService_core::getInfo()
   * 逻辑类型: undefined - undefined
   */
  async getInfo(site_id: number, id: number) {
    // 基于PHP真实逻辑: getInfo
    // PHP原文: $field = 'id, mobile,sms_type,key,template_id,content,params,status,result,create_time,send_time,update_time';         return $this->model->field($fie...
const field = 'id, mobile,sms_type,key,template_id,content,params,status,result,create_time,send_time,update_time';
        return this.model.field(field).where([['id', '=', id], ['site_id', '=', site_id))).append(['name', 'sms_type_name', 'status_name')).findOrEmpty().toArray(];
    }

    /**
     * 添加短信发送记录
     * @param int site_id
     * @param data
     * @return mixed|null
     */
    async add(int site_id, data)
    {
        data.site_id = site_id;
        const log = this.model.create(data);
        return log?.id;

    }

    /**
     * 短信发送记录编辑
     * @param int site_id
     * @param int id
     * @param data
     * @return true
     */
    async edit(int site_id, int id, data)
    {
        data.update_time = time(];
        this.model.where([['id', '=', id], ['site_id', '=', site_id))).update(data);
        return true;
    }

    /**
     * 删除短信发送记录
     * @param int site_id
     * @param int id
     * @return bool
     */
    async del(int site_id, int id)
    {
        return this.model.where([['id', '=', id], ['site_id', '=', site_id))).delete(;
  }
  }

  /**
   * add
   * 对应 PHP: CoreNoticeSmsLogService_core::add()
   * 逻辑类型: undefined - undefined
   */
  async add(site_id: any[], data: any[]) {
    // 基于PHP真实逻辑: add
    // PHP原文: $data['site_id'] = $site_id;         $log = $this->model->create($data);         return $log?->id;      }      /**      * 短信发送记录编辑      * @param int $...
data.site_id = site_id;
        const log = this.model.create(data);
        return log?.id;

    }

    /**
     * 短信发送记录编辑
     * @param int site_id
     * @param int id
     * @param data
     * @return true
     */
    async edit(int site_id, int id, data)
    {
        data.update_time = time(];
        this.model.where([['id', '=', id], ['site_id', '=', site_id))).update(data);
        return true;
    }

    /**
     * 删除短信发送记录
     * @param int site_id
     * @param int id
     * @return bool
     */
    async del(int site_id, int id)
    {
        return this.model.where([['id', '=', id], ['site_id', '=', site_id))).delete(;
  }
  }

  /**
   * edit
   * 对应 PHP: CoreNoticeSmsLogService_core::edit()
   * 逻辑类型: undefined - undefined
   */
  async edit(site_id: any[], id: any[], data: any[]) {
    // 基于PHP真实逻辑: edit
    // PHP原文: $data['update_time'] = time();         $this->model->where([['id', '=', $id], ['site_id', '=', $site_id]])->update($data);         return true;     } ...
data.update_time = time(];
        this.model.where([['id', '=', id], ['site_id', '=', site_id))).update(data);
        return true;
    }

    /**
     * 删除短信发送记录
     * @param int site_id
     * @param int id
     * @return bool
     */
    async del(int site_id, int id)
    {
        return this.model.where([['id', '=', id], ['site_id', '=', site_id))).delete(;
  }
  }

  /**
   * del
   * 对应 PHP: CoreNoticeSmsLogService_core::del()
   * 逻辑类型: undefined - undefined
   */
  async del(site_id: number, id: number) {
    // 基于PHP真实逻辑: del
    // PHP原文: return $this->model->where([['id', '=', $id], ['site_id', '=', $site_id]])->delete();     }   }...
return this.model.where([['id', '=', id], ['site_id', '=', site_id))).delete(;
  }
  }
}
